feat: standard schema for validation#543
Conversation
🦋 Changeset detectedLatest commit: 2ca6fa9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
ghostdevv
left a comment
There was a problem hiding this comment.
the jsdoc comments above the validate options would need updating, as well as the docs https://github.com/bombshell-dev/docs/
natemoo-re
left a comment
There was a problem hiding this comment.
Code looks great, changeset is perfect, just minor feedback on the example!
|
I also want to note that the PR does not support schema transforms (they will run but not be used). That would require more changes to represent input and output in types. Out of scope of this PR but if you're interested let me know! |
|
@ghostdevv docs PR is available at bombshell-dev/docs#42 |
|
Also, this would be breaking right? |
Co-authored-by: James Garbutt <43081j@users.noreply.github.com>
Co-authored-by: James Garbutt <43081j@users.noreply.github.com>
|
@43081j yeah I was also hesitating. I inlined it, the spec says it's absolutely fine |
@ghostdevv by "this", are you referring to input/output/transforms or this PR? |
Yea, as this PR changes the behavior of the |
|
I'm not sure it's fully breaking. No change as a user but it's true that if you are dealing with lower level APIs like in the date prompt, then it requires changes. So maybe it's a major for core and a minor for prompts |
Ah, I'm so sorry but I missed the fact that the old behavior is still available 🤦♀️ |
|
technically, we can strip the standard schema types down to only the parts we use too. but i'm happy either way. inlining it is better than pulling a dependency still |
|
I just checked and very little can be stripped, only |
Co-authored-by: Willow (GHOST) <ghostdevbusiness@gmail.com>
Co-authored-by: Willow (GHOST) <ghostdevbusiness@gmail.com>
ghostdevv
left a comment
There was a problem hiding this comment.
last thing 😄 otherwise lgtm
| /** | ||
| * Represents the `validate()` option. A function or a | ||
| * [Standard Schema](https://github.com/standard-schema/standard-schema) | ||
| * that validates user input. If a custom function is given, you should return a | ||
| * `string` or `Error` to show as a validation error, or `undefined` to accept the result. | ||
| */ |
There was a problem hiding this comment.
| /** | |
| * Represents the `validate()` option. A function or a | |
| * [Standard Schema](https://github.com/standard-schema/standard-schema) | |
| * that validates user input. If a custom function is given, you should return a | |
| * `string` or `Error` to show as a validation error, or `undefined` to accept the result. | |
| */ | |
| /** | |
| * A function or [Standard Schema](https://github.com/standard-schema/standard-schema) | |
| * that validates user input. If a custom function is given, you should return a | |
| * `string` or `Error` to show as a validation error, or `undefined` to accept the result. | |
| * | |
| * @example Using arktype | |
| * ```ts | |
| * import { text } from '@clack/prompts'; | |
| * import { type } from 'arktype'; | |
| * | |
| * const name = await text({ | |
| * message: 'Enter your name (letters only)', | |
| * validate: type('string.alpha').describe('Name can only contain letters'), | |
| * }); | |
| * ``` | |
| * | |
| * @example Custom validator | |
| * ```ts | |
| * import { text } from '@clack/prompts'; | |
| * | |
| * const age = await text({ | |
| * message: 'Enter your age:', | |
| * validate(value) { | |
| * if (!value) return 'Please enter a value'; | |
| * const num = parseInt(value); | |
| * if (isNaN(num)) return 'Please enter a valid number'; | |
| * if (num < 0 || num > 120) return 'Age must be between 0 and 120'; | |
| * return undefined; | |
| * }, | |
| * }); | |
| * ``` | |
| */ |
What does this PR do?
Allows using Standard Schema compatible libraries for
validate(). Discussed on Discord.Docs PR: bombshell-dev/docs#42
Type of change
Checklist
pnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure